class Solution:
    def maxRotateFunction(self, A: list) -> int:
        length = len(A)
        sum_A = sum(A)
        res = 0
        for i in range(length):
            res += i * A[i]
        F_A = res
        for i in range(1, length):
            F_A = F_A + sum_A - length * A[-i]
            res = max(res, F_A)
        return res


a = Solution()
print(a.maxRotateFunction([4, 3, 2, 6]))
